1 Imports System.IO
2 Imports System.Windows.Forms
3 Imports System.Net.Mail
4 Imports System.Data.OleDb
5 Imports System.Security.Permissions
6 Imports System.Text
7 Imports System.Security.Cryptography
8
9 Public Class frmUserENG
10
11 Dim connstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|datadirectory|\sis.accdb"
12 Dim connect As New OleDbConnection
13
14 #Region "Connections"
15 Public Sub openconnection()
16 If connect.State = ConnectionState.Closed Then
17 connect.ConnectionString = connstring
18 connect.Open()
19 ElseIf connect.State = ConnectionState.Open Then
20 Me.Refresh()
21 End If
22 End Sub
23
24 Public Sub closeconnection()
25 If connect.State = ConnectionState.Open Then
26 connect.Close()
27 ElseIf connect.State = ConnectionState.Closed Then
28 Me.Refresh()
29 End If
30 End Sub
31 #End Region
32
33 #Region "Buttons"
34 #Region "HOME"
35 Private Sub btnHome_Click(sender As System.Object, e As System.EventArgs) Handles btnHome.Click
36 enablebtns()
37 btnHome.Enabled = False
38 hidegb()
39 gbHome.Dock = DockStyle.Fill
40 gbHome.Show()
41 viewnews()
42 txthomesearch.Clear()
43 End Sub
44
45 Private Sub viewnews()
46 Dim selectqry As String = "SELECT * FROM news"
47 Dim da As OleDbDataAdapter
48 Dim dtset As New DataSet
49 Dim dttable As New DataTable
50 da = New OleDbDataAdapter(selectqry, connect)
51 da.Fill(dtset, "news")
52 dttable = dtset.Tables("news")
53
54 dgvHome.DataSource = dttable
55 dgvHome.ColumnHeadersDefaultCellStyle.Font = New Font(dgvHome.Font, FontStyle.Bold)
56 dgvHome.ForeColor = Color.Black
57 dgvHome.Font = New Font(dgvHome.Font, FontStyle.Regular)
58
59 dgvHome.Columns("ID").HeaderText = "News number"
60 dgvHome.Columns("ID").Width = 80
61
62 dgvHome.Columns("ntitle").HeaderText = "News Title"
63 dgvHome.Columns("ntitle").Width = 180
64
65 dgvHome.Columns("ndescription").HeaderText = "News Description"
66 dgvHome.Columns("ndescription").Width = 428
67
68 dgvHome.Columns("ntime").HeaderText = "Time Posted"
69 dgvHome.Columns("ntime").Width = 270
70 End Sub
71
72 Private Sub btnhomesearch_Click(sender As System.Object, e As System.EventArgs) Handles btnhomesearch.Click
73 Dim search As String = txthomesearch.Text.Trim
74 If (search = "" Or IsNothing(search) = True) Then
75 MsgBox("Please enter something to search", MsgBoxStyle.Information, "Error")
76 txthomesearch.Focus()
77 Else
78 txthomesearch.Clear()
79 Dim searchqry As String = "SELECT * FROM news WHERE id LIKE '%" + search + "%' OR ntitle LIKE '%" + search + "%' OR ndescription LIKE '%" + search + "%' OR ntime LIKE '%" + search + "%'"
80 Dim da As OleDbDataAdapter
81 Dim dtset As New DataSet
82 Dim dttable As New DataTable
83 da = New OleDbDataAdapter(searchqry, connect)
84 da.Fill(dtset, "news")
85 dttable = dtset.Tables("news")
86
87 dgvHome.DataSource = dttable
88 dgvHome.ColumnHeadersDefaultCellStyle.Font = New Font(dgvHome.Font, FontStyle.Bold)
89 dgvHome.ForeColor = Color.Black
90 dgvHome.Font = New Font(dgvHome.Font, FontStyle.Regular)
91
92 dgvHome.Columns("ID").HeaderText = "News number"
93 dgvHome.Columns("ID").Width = 80
94
95 dgvHome.Columns("ntitle").HeaderText = "News Title"
96 dgvHome.Columns("ntitle").Width = 180
97
98 dgvHome.Columns("ndescription").HeaderText = "News Description"
99 dgvHome.Columns("ndescription").Width = 428
100
101 dgvHome.Columns("ntime").HeaderText = "Time Posted"
102 dgvHome.Columns("ntime").Width = 270
103
104 End If
105 End Sub
106
107 Private Sub btnHomerefresh_Click(sender As System.Object, e As System.EventArgs) Handles btnHomerefresh.Click
108 viewnews()
109 End Sub
110 #End Region
111
112 #Region "SALE"
113
114 Private Sub btnsales_Click(sender As System.Object, e As System.EventArgs) Handles btnSales.Click
115 enablebtns()
116 btnSales.Enabled = False
117 hidegb()
118 gbSale.Dock = DockStyle.Fill
119 gbSale.Show()
120 clearinputs_sale()
121
122 Dim selectqry As String = "SELECT * FROM stock"
123 Dim da As OleDbDataAdapter
124 da = New OleDbDataAdapter(selectqry, connect)
125 Dim dtset As DataSet
126 dtset = New DataSet()
127 da.Fill(dtset, "stock")
128 Dim dttable As DataTable
129 dttable = New DataTable
130 dttable = dtset.Tables("stock")
131
132 Dim dbname As String
133 For Each temprow In dttable.Rows
134 dbname = temprow("pname").ToString
135 cbName.Items.Add(dbname)
136 Next
137
138 End Sub
139
140 Private Sub btnClearaddstock_Click(sender As System.Object, e As System.EventArgs) Handles btnClearaddstock.Click
141 clearinputs_sale()
142 End Sub
143
144 Private Sub btnSaveaddstock_Click(sender As System.Object, e As System.EventArgs) Handles btnSaleaddstock.Click
145 Dim pname As String = cbName.Text
146 Dim pcategory As String = cbcategory.Text.Trim
147 Dim pquantity As String = txtquantityaddstock.Text.Trim
148 Dim pselling As String = txtsellpriceaddstock.Text.Trim
149 Dim pinfo As String = txtInfoaddstock.Text.Trim
150 Dim ptime As String = lblTime.Text.Trim & " " & lblDate.Text.Trim
151 Dim pquantityremain, pprofit As String
152
153
154 Dim selectqry As String = "SELECT * FROM stock WHERE pname='" + pname + "' AND pcategory='" + pcategory + "'"
155 Dim da As OleDbDataAdapter
156 da = New OleDbDataAdapter(selectqry, connect)
157 Dim dtset As DataSet
158 dtset = New DataSet()
159 da.Fill(dtset, "stock")
160 Dim dttable As DataTable
161 dttable = New DataTable
162 dttable = dtset.Tables("stock")
163
164 Dim dbquantity, dbbuying As String
165 For Each temprow In dttable.Rows
166 dbquantity = temprow("pquantity").ToString
167 dbbuying = temprow("pbuying").ToString
168 Next
169
170 If pname.Length < 2 Then
171 MsgBox("Product name can not be less than 2 characters", MessageBoxIcon.Warning, "Error")
172 cbName.Focus()
173 ElseIf pname.Length > 25 Then
174 MsgBox("Product name can not be more than 25 characters", MessageBoxIcon.Warning, "Error")
175 cbName.Focus()
176
177 ElseIf cbcategory.Text = "" Then
178 MsgBox("Please select product category", MessageBoxIcon.Warning, "Error")
179 cbcategory.Focus()
180
181 ElseIf IsNumeric(pquantity) = False Then
182 MsgBox("Only numbers are allowed in quantity", MessageBoxIcon.Warning, "Error")
183 txtquantityaddstock.Focus()
184 Exit Sub
185 ElseIf pquantity.Length > 25 Then
186 MsgBox("Product quantity can not be more than 25 digits", MessageBoxIcon.Warning, "Error")
187 txtquantityaddstock.Focus()
188 Exit Sub
189
190 ElseIf IsNumeric(pselling) = False Then
191 MsgBox("Only numbers are allowed in selling price", MessageBoxIcon.Warning, "Error")
192 txtsellpriceaddstock.Focus()
193 ElseIf pselling.Length > 25 Then
194 MsgBox("Product selling price can not be more than 25 digits", MessageBoxIcon.Warning, "Error")
195 txtsellpriceaddstock.Focus()
196
197 ElseIf pinfo.Length < 2 Then
198 MsgBox("Product informations can't be less than 2 characters", MessageBoxIcon.Warning, "Error")
199 txtInfoaddstock.Focus()
200
201 ElseIf txtInfoaddstock.Text = "" Then
202 MsgBox("Please enter information about the product", MessageBoxIcon.Warning, "Error")
203 txtInfoaddstock.Focus()
204
205 Else
206 'for log file
207 'Dim uname As String =frmlogin.lbluname.text
208 Dim uname As String = "cngirwa"
209 Dim activity As String = uname + " sold a product with name " + pname
210 Dim activitydate As String = lblTime.Text + " " + lblDate.Text
211 Dim insertlog As String = "INSERT INTO logfiles VALUES('" + uname + "','" + activity + "','" + activitydate + "')"
212 Dim insertlogcmd As New OleDbCommand
213 With insertlogcmd
214 .CommandText = insertlog
215 .Connection = connect
216 .ExecuteNonQuery()
217 End With
218
219 pquantityremain = dbquantity - pquantity
220 pprofit = pselling - dbbuying
221
222 Dim updateqry As String = "UPDATE stock SET pquantity='" + pquantityremain + "' WHERE pname='" + pname + "' AND pcategory='" + pcategory + "' "
223 Dim updatecmd As New OleDbCommand
224 With updatecmd
225 .CommandText = updateqry
226 .Connection = connect
227 .ExecuteNonQuery()
228 End With
229
230 Dim insertqry As String = "INSERT INTO sales(pname,pcategory,pquantitysold,pquantityremain,pselling,pprofit,pinfo,pdate) VALUES('" + pname + "','" + pcategory + "','" + pquantity + "','" + pquantityremain + "','" + pselling + "','" + pprofit + "','" + pinfo + "','" + ptime + "')"
231 Dim insertcmd As New OleDbCommand
232 With insertcmd
233 .CommandText = insertqry
234 .Connection = connect
235 .ExecuteNonQuery()
236 End With
237 MsgBox("Product sold", MsgBoxStyle.Information, "Success")
238 clearinputs_sale()
239 End If
240 End Sub
241
242 Private Sub cbName_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cbName.SelectedIndexChanged
243 cbcategory.Items.Clear()
244 Dim selectqrycat As String = "SELECT * FROM stock WHERE pname='" + cbName.SelectedItem.ToString + "'"
245 Dim dacat As OleDbDataAdapter
246 dacat = New OleDbDataAdapter(selectqrycat, connect)
247 Dim dtsetcat As DataSet
248 dtsetcat = New DataSet()
249 dacat.Fill(dtsetcat, "stock")
250 Dim dttablecat As DataTable
251 dttablecat = New DataTable
252 dttablecat = dtsetcat.Tables("stock")
253
254 Dim dbcategory As String
255 For Each temprow In dttablecat.Rows
256 dbcategory = temprow("pcategory").ToString
257 cbcategory.Items.Add(dbcategory)
258 Next
259 End Sub
260
261 Private Sub txtquantityaddstock_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtquantityaddstock.TextChanged
262 Dim pquantity As String = txtquantityaddstock.Text.Trim
263 If pquantity = "" Then
264 txtquantityaddstock.Clear()
265 Exit Sub
266 ElseIf IsNumeric(pquantity) = False Then
267 MsgBox("Only numbers are allowed with no space", MessageBoxIcon.Warning, "Error")
268 txtquantityaddstock.Clear()
269 txtquantityaddstock.Focus()
270 Exit Sub
271 ElseIf pquantity.Length > 25 Then
272 MsgBox("Product quantity can not be more than 25 digits", MessageBoxIcon.Warning, "Error")
273 txtquantityaddstock.Clear()
274 txtquantityaddstock.Focus()
275 Exit Sub
276 End If
277 End Sub
278
279 Private Sub txtsellpriceaddstock_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtsellpriceaddstock.TextChanged
280 Dim pselling As String = txtsellpriceaddstock.Text.Trim
281 If pselling = "" Then
282 txtsellpriceaddstock.Clear()
283 Exit Sub
284 ElseIf IsNumeric(pselling) = False Then
285 MsgBox("Only numbers are allowed with no space", MessageBoxIcon.Warning, "Error")
286 txtsellpriceaddstock.Clear()
287 txtsellpriceaddstock.Focus()
288 Exit Sub
289 ElseIf pselling.Length > 25 Then
290 MsgBox("Product selling price can not be more than 25 digits", MessageBoxIcon.Warning, "Error")
291 txtsellpriceaddstock.Clear()
292 txtsellpriceaddstock.Focus()
293 Exit Sub
294 End If
295 End Sub
296
297 Private Sub clearinputs_sale()
298 txtInfoaddstock.Clear()
299 txtquantityaddstock.Clear()
300 txtsellpriceaddstock.Clear()
301 End Sub
302 #End Region
303
304 #Region "VIEW STORE"
305 Private Sub btnViewstock_Click(sender As System.Object, e As System.EventArgs) Handles btnViewstock.Click
306 enablebtns()
307 btnViewstock.Enabled = False
308 hidegb()
309 gbViewstock.Dock = DockStyle.Fill
310 gbViewstock.Show()
311 viewstock()
312 End Sub
313
314 Private Sub btnViewstorerefresh_Click(sender As System.Object, e As System.EventArgs) Handles btnViewstorerefresh.Click
315 viewstock()
316 End Sub
317
318 Private Sub viewstock()
319 'for log file
320 'Dim uname As String =frmlogin.lbluname.text
321 Dim uname As String = "cngirwa"
322 Dim activity As String = uname + " viewed stock "
323 Dim activitydate As String = lblTime.Text + " " + lblDate.Text
324 Dim insertlog As String = "INSERT INTO logfiles VALUES('" + uname + "','" + activity + "','" + activitydate + "')"
325 Dim insertlogcmd As New OleDbCommand
326 With insertlogcmd
327 .CommandText = insertlog
328 .Connection = connect
329 .ExecuteNonQuery()
330 End With
331
332 Dim selectqry As String = "SELECT id,pname,pcategory,pquantity,pselling,pinfo,pdate FROM stock"
333 Dim da As OleDbDataAdapter
334 Dim dtset As DataSet
335 Dim dttable As New DataTable
336
337 da = New OleDbDataAdapter(selectqry, connect)
338 dtset = New DataSet
339 da.Fill(dtset, "stock")
340 dttable = dtset.Tables("stock")
341
342 dgvViewstore.DataSource = dttable
343 dgvViewstore.ColumnHeadersDefaultCellStyle.Font = New Font(dgvViewstore.Font, FontStyle.Bold)
344 dgvViewstore.Font = New Font(dgvViewstore.Font, FontStyle.Regular)
345 dgvViewstore.ForeColor = Color.Black
346
347 dgvViewstore.Columns("ID").HeaderText = "S/N"
348 dgvViewstore.Columns("ID").Width = 35
349
350 dgvViewstore.Columns("pname").HeaderText = "Product name"
351 dgvViewstore.Columns("pname").Width = 160
352
353 dgvViewstore.Columns("pcategory").HeaderText = "Category"
354 dgvViewstore.Columns("pcategory").Width = 90
355
356 dgvViewstore.Columns("pquantity").HeaderText = "Quantity Remain"
357 dgvViewstore.Columns("pquantity").Width = 70
358
359 dgvViewstore.Columns("pselling").HeaderText = "Selling Price"
360 dgvViewstore.Columns("pselling").Width = 70
361
362 dgvViewstore.Columns("pinfo").HeaderText = "Description of Product"
363 dgvViewstore.Columns("pinfo").Width = 270
364
365 dgvViewstore.Columns("pdate").HeaderText = "Date"
366 dgvViewstore.Columns("pdate").Width = 270
367
368 End Sub
369
370 Private Sub btnViewstoresearch_Click(sender As System.Object, e As System.EventArgs) Handles btnViewstoresearch.Click
371 Dim search As String = txtViewstoresearch.Text.Trim
372 If (search = "" Or IsNothing(search) = True) Then
373 MsgBox("Please enter something to search", MsgBoxStyle.Information, "Error")
374 txtViewstoresearch.Focus()
375 Else
376 txtViewstoresearch.Clear()
377 Dim searchqry As String = "SELECT id,pname,pcategory,pquantity,pselling,pinfo,pdate FROM stock WHERE id LIKE '%" + search + "%' OR pname LIKE '%" + search + "%' OR pcategory LIKE '%" + search + "%' OR pquantity LIKE '%" + search + "%' OR pselling LIKE '%" + search + "%' OR pinfo LIKE '%" + search + "%' OR pdate LIKE '%" + search + "%'"
378 Dim da As OleDbDataAdapter
379 Dim dtset As DataSet
380 Dim dttable As New DataTable
381
382 da = New OleDbDataAdapter(searchqry, connect)
383 dtset = New DataSet
384 da.Fill(dtset, "stock")
385 dttable = dtset.Tables("stock")
386
387 dgvViewstore.DataSource = dttable
388 dgvViewstore.ColumnHeadersDefaultCellStyle.Font = New Font(dgvViewstore.Font, FontStyle.Bold)
389 dgvViewstore.Font = New Font(dgvViewstore.Font, FontStyle.Regular)
390 dgvViewstore.ForeColor = Color.Black
391
392 dgvViewstore.Columns("ID").HeaderText = "S/N"
393 dgvViewstore.Columns("ID").Width = 35
394
395 dgvViewstore.Columns("pname").HeaderText = "Product Name"
396 dgvViewstore.Columns("pname").Width = 160
397
398 dgvViewstore.Columns("pcategory").HeaderText = "Category"
399 dgvViewstore.Columns("pcategory").Width = 90
400
401 dgvViewstore.Columns("pquantity").HeaderText = "Quantity Remain"
402 dgvViewstore.Columns("pquantity").Width = 70
403
404 dgvViewstore.Columns("pselling").HeaderText = "Selling Price"
405 dgvViewstore.Columns("pselling").Width = 70
406
407 dgvViewstore.Columns("pinfo").HeaderText = "Description of Product"
408 dgvViewstore.Columns("pinfo").Width = 270
409
410 dgvViewstore.Columns("pdate").HeaderText = "Date"
411 dgvViewstore.Columns("pdate").Width = 270
412 End If
413 End Sub
414 #End Region
415
416 #Region "SETTING"
417
418 Private Sub btnSettings_Click(sender As System.Object, e As System.EventArgs) Handles btnSettings.Click
419 enablebtns()
420 btnSettings.Enabled = False
421 hidegb()
422 gbSetting.Dock = DockStyle.Fill
423 gbSetting.Show()
424 clearinputs_settings()
425 End Sub
426
427 Private Sub btnChangepass_Click(sender As System.Object, e As System.EventArgs) Handles btnChangepass.Click
428 Dim oldpass As String = txtOldpass.Text.Trim
429 Dim newpass As String = txtNewpass.Text.Trim
430 Dim repeat As String = txtRepeat.Text.Trim
431 'Dim uname As String =frmlogin.lbluname.text
432 Dim uname As String = "cngirwa"
433
434 Dim Ueold As New UnicodeEncoding()
435 Dim ByteSourceTextold() As Byte = Ueold.GetBytes(oldpass)
436 Dim Md5old As New MD5CryptoServiceProvider()
437 Dim ByteHashold() As Byte = Md5old.ComputeHash(ByteSourceTextold)
438 Convert.ToBase64String(ByteHashold)
439 Dim hashPwdold As String
440 hashPwdold = Convert.ToBase64String(ByteHashold)
441
442 Dim selectqry As String = "SELECT * FROM users WHERE uname='" + uname + "'"
443 Dim da As OleDbDataAdapter
444 da = New OleDbDataAdapter(selectqry, connect)
445 Dim dtset As DataSet
446 dtset = New DataSet()
447 da.Fill(dtset, "users")
448 Dim dttable As DataTable
449 dttable = New DataTable
450 dttable = dtset.Tables("users")
451
452 Dim dbuname, dbpass As String
453 For Each temprow In dttable.Rows
454 dbuname = temprow("uname").ToString
455 dbpass = temprow("upass").ToString
456 Next
457
458 Dim Uenew As New UnicodeEncoding()
459 Dim ByteSourceTextnew() As Byte = Uenew.GetBytes(newpass)
460 Dim Md5new As New MD5CryptoServiceProvider()
461 Dim ByteHashnew() As Byte = Md5new.ComputeHash(ByteSourceTextnew)
462 Convert.ToBase64String(ByteHashnew)
463 Dim hashPwdnew As String
464 hashPwdnew = Convert.ToBase64String(ByteHashnew)
465
466 If (oldpass = "" Or IsNothing(oldpass) = True) Then
467 MsgBox("Please enter old password", MessageBoxIcon.Warning, "Error")
468 txtOldpass.Focus()
469 ElseIf (newpass = "" Or IsNothing(newpass) = True) Then
470 MsgBox("Please enter new password", MessageBoxIcon.Warning, "Error")
471 txtNewpass.Focus()
472 ElseIf (repeat = "" Or IsNothing(repeat) = True) Then
473 MsgBox("Please enter new password again", MessageBoxIcon.Warning, "Error")
474 txtRepeat.Focus()
475 ElseIf (dbpass <> hashPwdold) Then
476 MsgBox("Old password did not match", MessageBoxIcon.Warning, "Error")
477 txtOldpass.Focus()
478 ElseIf (newpass <> repeat) Then
479 MsgBox("New password did not match", MessageBoxIcon.Warning, "Error")
480 txtNewpass.Focus()
481 ElseIf (hashPwdnew = dbpass) Then
482 MsgBox("New password is the same as old password. Please enter new password", MessageBoxIcon.Warning, "Error")
483 txtNewpass.Focus()
484 Else
485 'for log file
486 Dim activity As String = uname + " changed password "
487 Dim activitydate As String = lblTime.Text + " " + lblDate.Text
488 Dim insertlog As String = "INSERT INTO logfiles VALUES('" + uname + "','" + activity + "','" + activitydate + "')"
489 Dim insertlogcmd As New OleDbCommand
490 With insertlogcmd
491 .CommandText = insertlog
492 .Connection = connect
493 .ExecuteNonQuery()
494 End With
495
496 Dim updateqry As String = "UPDATE users SET upass='" + hashPwdnew + "' WHERE uname='" + uname + "'"
497 Dim updatecmd As New OleDbCommand
498 With updatecmd
499 .CommandText = updateqry
500 .Connection = connect
501 .ExecuteNonQuery()
502 End With
503 MsgBox("Password updated", MsgBoxStyle.Information, "Success")
504 clearinputs_settings()
505 End If
506 End Sub
507
508 Private Sub clearinputs_settings()
509 txtOldpass.Clear()
510 txtNewpass.Clear()
511 txtRepeat.Clear()
512 End Sub
513 #End Region
514
515 #Region "HELP"
516 Private Sub btnHelp_Click(sender As System.Object, e As System.EventArgs) Handles btnHelp.Click
517 enablebtns()
518 btnHelp.Enabled = False
519 hidegb()
520 gbHelp.Dock = DockStyle.Fill
521 gbHelp.Show()
522 End Sub
523 #End Region
524
525 #Region "LOGOUT"
526 Private Sub btnLogout_Click(sender As System.Object, e As System.EventArgs) Handles btnLogout.Click
527 Dim logout As String
528 logout = MessageBox.Show("Are you sure you want to logout?", "Stationary Information System", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
529 If logout = MsgBoxResult.No Then
530 Me.Refresh()
531 enablebtns()
532 btnHome.Enabled = False
533 hidegb()
534 gbHome.Dock = DockStyle.Fill
535 gbHome.Show()
536 Else
537 'for log file
538 Dim uname As String = frmLogin.lbluname.Text
539 Dim unamelog As String = uname
540 Dim activity As String = unamelog + " logged out "
541 Dim activitydate As String = lblTime.Text + " " + lblDate.Text
542 Dim insertlog As String = "INSERT INTO logfiles VALUES('" + unamelog + "','" + activity + "','" + activitydate + "')"
543 Dim insertlogcmd As New OleDbCommand
544 With insertlogcmd
545 .CommandText = insertlog
546 .Connection = connect
547 .ExecuteNonQuery()
548 End With
549
550 Dim updateqry As String = "UPDATE users SET access='LOGOUT' WHERE uname='" + uname + "'"
551 Dim updatecmd As New OleDbCommand
552 With updatecmd
553 .CommandText = updateqry
554 .Connection = connect
555 .ExecuteNonQuery()
556 End With
557
558 frmLogin.Show()
559 Me.Dispose()
560 closeconnection()
561 End If
562 End Sub
563 #End Region
564 #End Region
565
566 #Region "Form actions"
567 Private Sub frmuserENG_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
568 openconnection()
569 Dim close As String
570 close = MessageBox.Show("Are you sure you want to close?", "Stationary Information System", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
571 If close = MsgBoxResult.No Then
572 Me.Refresh()
573 e.Cancel = True
574 Else
575 Dim uname As String = frmLogin.lbluname.Text
576 Dim unamelog As String = uname
577 Dim activity As String = unamelog + " logged out "
578 Dim activitydate As String = lblTime.Text + " " + lblDate.Text
579 Dim insertlog As String = "INSERT INTO logfiles VALUES('" + unamelog + "','" + activity + "','" + activitydate + "')"
580 Dim insertlogcmd As New OleDbCommand
581 With insertlogcmd
582 .CommandText = insertlog
583 .Connection = connect
584 .ExecuteNonQuery()
585 End With
586
587 Dim updateqry As String = "UPDATE users SET access='LOGOUT' WHERE uname='" + uname + "'"
588 Dim updatecmd As New OleDbCommand
589 With updatecmd
590 .CommandText = updateqry
591 .Connection = connect
592 .ExecuteNonQuery()
593 End With
594
595 frmLogin.Show()
596 Me.Dispose()
597 closeconnection()
598 End If
599 End Sub
600
601 Private Sub frmuserENG_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
602 TimerDate.Start()
603 hidegb()
604 gbHome.Dock = DockStyle.Fill
605 gbHome.Show()
606 enablebtns()
607 btnHome.Enabled = False
608 openconnection()
609 viewnews()
610 End Sub
611
612 #End Region
613
614 #Region "Time, Date and Zone"
615 Private Sub TimerDate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerDate.Tick
616 lblTime.Text = TimeOfDay
617 lblDate.Text = Today.Date.ToString("dddd, dd MMMM yyyy")
618 lblZone.Text = TimeZone.CurrentTimeZone.StandardName
619 End Sub
620 #End Region
621
622 #Region "Hide all gb"
623 Private Sub hidegb()
624 gbHome.Hide()
625 gbSale.Hide()
626 gbViewstock.Hide()
627 gbSetting.Hide()
628 gbHelp.Hide()
629 End Sub
630 #End Region
631
632 #Region "Enable all Buttons"
633 Private Sub enablebtns()
634 btnHome.Enabled = True
635 btnSales.Enabled = True
636 btnViewstock.Enabled = True
637 btnSettings.Enabled = True
638 btnHelp.Enabled = True
639 End Sub
640 #End Region
641
642 #Region "notification icon"
643 Private Sub frmuserENG_Move(sender As Object, e As System.EventArgs) Handles Me.Move
644 If Me.WindowState = FormWindowState.Minimized Then
645 Me.Hide()
646 niSIS.ShowBalloonTip(4600, "Stationary Information System", "Stationary Information System have been minimized. Click this icon to maximise it", ToolTipIcon.Info)
647 End If
648 End Sub
649
650 Private Sub niSIS_MouseDoubleClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles niSIS.MouseDoubleClick
651 Me.Show()
652 Me.WindowState = FormWindowState.Normal
653 End Sub
654 #End Region
655
656 End Class